package net.sxnic.normal.listener;

import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import net.sxnic.ugr.UgrConstant;
import net.sxnic.ugr.context.AppContext;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 
 * Introduction：session listener
 * 
 * @author 孙宇飞 create date : 2009-4-6
 */
public class AppSessionListener implements HttpSessionListener,
		HttpSessionBindingListener {
	private static Log log = LogFactory.getLog(AppSessionListener.class);
	private int sessionCount;
	private int sessioncount1;
	private String logMsg;

	public void sessionCreated(HttpSessionEvent event) {
	}

	/**
	 * 当session失效时 从登陆用户map中剔除此用户
	 */
	public void sessionDestroyed(HttpSessionEvent event) {
		String logoutUserName = (String) event.getSession().getAttribute(
				AppContext.APPCONTEXT_USERNAME);
		if (StringUtils.isNotBlank(logoutUserName)
				&& UgrConstant.LOGIN_USER_MAP.containsKey(logoutUserName)) {
			UgrConstant.LOGIN_USER_MAP.remove(logoutUserName);
		}
	}

	public int getSessionCount() {
		return sessionCount;
	}

	public void setSessionCount(int sessionCount) {
		this.sessionCount = sessionCount;
	}

	public String getLogMsg() {
		return logMsg;
	}

	public void setLogMsg(String logMsg) {
		this.logMsg = logMsg;
	}

	public int getSessioncount1() {
		return sessioncount1;
	}

	public void setSessioncount1(int sessioncount1) {
		this.sessioncount1 = sessioncount1;
	}

	@Override
	public void valueBound(HttpSessionBindingEvent arg0) {
		// TODO Auto-generated method stub

		log.debug("1---" + arg0.getName());

	}

	@Override
	public void valueUnbound(HttpSessionBindingEvent arg0) {
		// TODO Auto-generated method stub
		log.debug("34----" + arg0.getName());
	}

}
